import axios from 'axios'
import {baseURL} from '../configFile'
import ManufacturerInfo from "../types/ManufacturerInfo";

const axiosReq = axios.create({
    baseURL
})

//全部厂商列表请求
export const listManufacturer = (offset: number, limit: number) => {
    return axiosReq.get('/listManufacturer', { params: { offset, limit } })
}

//根据用户ID请求所属厂商列表
export const listManufacturerOnID = (offset: number, limit: number, userID: number) => {
    return axiosReq.get('/listManufacturerOnID', { params: { offset, limit, userID } })
}

//全部厂商数量请求
export const queryManufacturerInfoAmount = () => {
    return axiosReq.get('/queryManufacturerInfoAmount')
}

//根据用户ID请求所属厂商数量
export const queryManufacturerInfoAmountOnID = (userID: number) => {
    return axiosReq.get('/queryManufacturerInfoAmountOnID', { params: { userID } })
}

//添加厂商
export const addManufacturer = (manufacturerName: string, manufacturerTelephone: string, manufacturerAddress: string, manufacturerIntroduction: String) => {
    return axiosReq.post('/addManufacturer', { manufacturerName, manufacturerTelephone, manufacturerAddress, manufacturerIntroduction })
}

//修改厂商信息
export const modifyManufacturer = (manufacturerInfo: ManufacturerInfo) => {
    return axiosReq.post('/modifyManufacturer', { manufacturerInfo })
}

//删除厂商
export const deleteManufacturer = (manufacturerID: number) => {
    return axiosReq.post('/deleteManufacturer', { 'manufacturerID': manufacturerID })
}

//根据关键词搜索具体厂商
export const searchManufacturer = (keyword: string) => {
    return axiosReq.get('/searchManufacturer', { params: { keyword } })
}

//搜索特定厂商（已删除）
export const searchDeletedManufacturer = (keyword: string) => {
    return axiosReq.get('/searchDeletedManufacturer', { params: { keyword } })
}

//根据厂商id查询厂商信息
export const queryManufacturer = (manufacturerInfoID: number) => {
    return axiosReq.get('/queryManufacturer', { params: { manufacturerInfoID } })
}

//恢复已删除厂商
export const deletedManufacturerRecover = (manufacturerID: number) => {
    return axiosReq.post('/deletedManufacturerRecover', {  manufacturerID  })
}

//列出已删除厂商
export const listDeletedManufacturer = (offset: number, limit: number) => {
    return axiosReq.get('/listDeletedManufacturer', { params: { offset, limit } })
}

//已删除厂商数量
export const queryDeletedManufacturerAmount = () => {
    return axiosReq.get('/queryDeletedManufacturerInfoAmount')
}

//用户加入厂商
export const userJoinManufacturer = (manufacturerID:number) => {
    return axiosReq.post('/userJoinManufacturer',{manufacturerID})
}

//用户退出厂商
export const userLeaveManufacturer = (manufacturerID:number) => {
    return axiosReq.post('/userLeaveManufacturer',{'manufacturerID':manufacturerID})
}

//通过邮编获得地址信息
export const getAreaName = (areaCode: string) => {
    return axiosReq.get('/getAreaName', { params: { areaCode } })
}

//根据用户搜索厂商信息
export const searchManufacturerOnID = (keyword:string) => {
    return axiosReq.get('/searchManufacturerOnID',{params:{keyword}})
}

//搜索用户未加入厂商
export const searchManufacturerNotJoin = (keyword:string) => {
    return axiosReq.get('/searchManufacturerNotJoin',{params:{keyword}})
}